package com.eclipse.e0112_多线程.死锁;

public class DeadLock {
    private final Object monitor1 = new Object();
    private final Object monitor2 = new Object();
    
    private void setName(int name){
        synchronized (monitor1){
            name = 1;
            //线程1运行到此处的时候，被线程2打断，跑到setAge中
            synchronized (monitor2){
                name = 2;
            }
        }
    }
    
    private void setAge(int age){
        synchronized (monitor2){
            age = 1;
            //线程是运行到此处，就会出现死锁
            synchronized (monitor1){
                age = 2;
            }
        }
    }
  //上面的代码中，注释里面有详细说明。monitor1和monitor2在相互等待对方运行完成，导致死锁产生。
}
